<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class UserScore extends Model
{
    public $table = 'user_score';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['user_id','type_id','type','host_rel'];

    /**
     * 男生-游客
     */
    const MALE_TOURIST = 1;

    /**
     * 男生-下游
     */
    const MALE_DOWNSTREAM = 2;

    /**
     * 男生-中游
     */
    const MALE_MIDSTREAM = 3;

    /**
     * 男生-上游
     */
    const MALE_UPSTREAM = 4;


    /**
     * 女生-新人
     */
    const FEMALE_NEWCOMER = 5;


    /**
     * 女生-推荐/普通
     */
    const FEMALE_POTENTIAL = 6;

    /**
     * 女生-潜力
     */
    const FEMALE_RECOMMEND = 7;

    /**
     * 女生-优质
     */
    const FEMALE_OPTIMIZE = 8;

    /**
     * 男生等级代号
     */
    const MALE_TOURIST_CODE = 'A';
    const MALE_DOWNSTREAM_CODE = 'B';
    const MALE_MIDSTREAM_CODE = 'C';
    const MALE_UPSTREAM_CODE = 'D';

    /**
     * 是否验证
     */
    const HOST_REL_OK = 1;
    const HOST_REL_NO = 0;


    const GRADE_ARRAY_NUM = [
        self::MALE_TOURIST,
        self::MALE_DOWNSTREAM,
        self::MALE_MIDSTREAM,
        self::MALE_UPSTREAM,
        self::FEMALE_NEWCOMER,
        self::FEMALE_POTENTIAL,
        self::FEMALE_RECOMMEND,
        self::FEMALE_OPTIMIZE
    ];

    /**
     * 男士等级 type_id == code
     */
    const MALE_GRADE_ARRAY = [
        null => '未评级',
        self::MALE_TOURIST => self::MALE_TOURIST_CODE,
        self::MALE_DOWNSTREAM => self::MALE_DOWNSTREAM_CODE,
        self::MALE_MIDSTREAM => self::MALE_MIDSTREAM_CODE,
        self::MALE_UPSTREAM => self::MALE_UPSTREAM_CODE
    ];

    /**
     * 男生等级代号
     */
    const FEMALE_NEWCOMER_CODE = 'H';
    const FEMALE_POTENTIAL_CODE = 'G';
    const FEMALE_RECOMMEND_CODE = 'F';
    const FEMALE_OPTIMIZE_CODE = 'E';

    /**
     * 女生等级
     */
    const FEMALE_GRADE_ARRAY = [
        null => '未评级',
        self::FEMALE_NEWCOMER => self::FEMALE_NEWCOMER_CODE,
        self::FEMALE_POTENTIAL => self::FEMALE_POTENTIAL_CODE,
        self::FEMALE_RECOMMEND => self::FEMALE_RECOMMEND_CODE,
        self::FEMALE_OPTIMIZE => self::FEMALE_OPTIMIZE_CODE
    ];

    const GRADE_ARRAY = [
        self::FEMALE_NEWCOMER => self::FEMALE_NEWCOMER_CODE,
        self::FEMALE_POTENTIAL => self::FEMALE_POTENTIAL_CODE,
        self::FEMALE_RECOMMEND => self::FEMALE_RECOMMEND_CODE,
        self::FEMALE_OPTIMIZE => self::FEMALE_OPTIMIZE_CODE,
        self::MALE_TOURIST => self::MALE_TOURIST_CODE,
        self::MALE_DOWNSTREAM => self::MALE_DOWNSTREAM_CODE,
        self::MALE_MIDSTREAM => self::MALE_MIDSTREAM_CODE,
        self::MALE_UPSTREAM => self::MALE_UPSTREAM_CODE
    ];


    const FEMALE_GRADE_TEXT_ARRAY = [
        null => '未评级',
        self::FEMALE_NEWCOMER => '新人',
        self::FEMALE_POTENTIAL => '潜力',
        self::FEMALE_RECOMMEND => '推荐',
        self::FEMALE_OPTIMIZE => '优质',
    ];

    const HOST_REL = [
        self::HOST_REL_OK => '验证',
        self::HOST_REL_NO => '未验证'
    ];

    const MALE_GRADE_TEXT_ARRAY = [
        null => '未评级',
        self::MALE_TOURIST => '游客',
        self::MALE_DOWNSTREAM => '下游',
        self::MALE_MIDSTREAM => '中游',
        self::MALE_UPSTREAM => '上游'
    ];

    const GRADE_TEXT_ARRAY = [
        self::FEMALE_NEWCOMER => '新人',
        self::FEMALE_POTENTIAL => '潜力',
        self::FEMALE_RECOMMEND => '推荐',
        self::FEMALE_OPTIMIZE => '优质',
        self::MALE_TOURIST => '游客',
        self::MALE_DOWNSTREAM => '下游',
        self::MALE_MIDSTREAM => '中游',
        self::MALE_UPSTREAM => '上游'
    ];

    const FIX_OPERATE = 1;
    const AUTO_OPERATE = 2;

    const OPERATE_ARRAY = [
        self::FIX_OPERATE => '手动调节固定',
        self::AUTO_OPERATE => '系统自动调节'
    ];

    public static function getUserType(int $userId) :int
    {
        $scoreLog = self::where(['user_id' => $userId])->first();

        if (empty($scoreLog)) {
            return 0;
        }

        return $scoreLog->type_id;
    }

    public static function getInfoByUserId($userId)
    {
        return self::where('user_id',$userId)->first();
    }
}
